/*
 *  Utils.h
 *
 *
 *  Created by Akito van Troyer on 12/1/10.
 *  Copyright 2010 Akito van Troyer. All rights reserved.
 *
 */

#ifndef UTIL_H_
#define UTIL_H_

#include <inttypes.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <string.h>
#include <util/delay.h>
#include <math.h>

#define cbi(port,pin)  port &= ~_BV(pin)
#define sbi(port,pin)  port |= _BV(pin)
#define toggle(port,pin) port ^= _BV(pin)
#define bit_test(byte,bit) (byte & (1 << bit)) // test for bit set
#define pin_test(pins,pin) (pins & (1<<pin))

#define FIXEDPT 10

uint8_t get_random8(uint8_t seed);
uint16_t get_random16(uint16_t seed);
uint16_t scale(uint16_t num, uint16_t minNum,uint16_t maxNum,uint16_t scaleMin,uint16_t scaleMax);

int32_t fp2int(int32_t num);
int32_t int2fp(int32_t num);
uint32_t fpfix(uint8_t num);

#endif //UTIL_H_
